<?php

namespace app\services;

class SwooleInit
{
    public function handle() {
        // 添加艺术字横幅
        // 添加艺术字横幅
        echo PHP_EOL;
        echo "      (\___/)     \n";
        echo "      (o   o)     \n";
        echo "      /  ~  \     \n";
        echo "     (_______)    \n";
        echo "     /       \    \n";
        echo "    /         \   \n";
        echo "   (  (     )  )  \n";
        echo "  (   \_____/   ) \n";
        echo " (_______________)\n";
        echo PHP_EOL;

        $swoole = config('swoole');
        $labels = [
            "start_at",
            "worker_num",
            "websocket",
            "hot_update",
            "queue"
        ];

        // 动态计算最大宽度（右对齐基准）
        $maxWidth = max(array_map('strlen', $labels)) + 2; // 增加额外间距

        foreach ($labels as $label) {
            $value = match($label) {
                "start_at"     => $swoole['http']['host'] . ":" . $swoole['http']['port'],
                "worker_num" => $swoole['http']['worker_num'],
                "websocket"  => $swoole['websocket']['enable'] ? "enable" : "disable",
                "hot_update"       => $swoole['hot_update']['enable'] ? "enable" : "disable",
                "queue"            => $swoole['queue']['enable'] ? "enable" : "disable"
            };
            printf("%{$maxWidth}s : %-s\n", $label, $value); // 组合控制符
        }
//        echo "SwooleInited" . PHP_EOL;
    }
}